
const request = require('../../../utils/request');
var app = getApp();
Page({
    data:{
        openGId: 0,
        shareTicket: app.globalData.shareTicket,
        userId: wx.getStorageSync('userId'),
        userHeaderUrl: '',
        userName: '',
        count: 0,   //邀请了多少人
        money: 0,   //邀请获得的金额
        seeCode: false,  //查看二维码,
        qrCode: ''
    },
    onLoad(e) {
        wx.showShareMenu({
            withShareTicket: true
        })
        //判断有没有登录
        console.log(e)
        if(!wx.getStorageSync('sessionId')){
            wx.navigateTo({
                url: '../../../pages/my/myLogin/myLogin'
            })
        }

        //获取本地存储头像，名字
        let that = this
        wx.getStorage({
            key: 'user',
            success: function(res){
                console.log(res)
                that.setData({
                    userHeaderUrl: res.data.userHeaderUrl,
                    userName: res.data.userName,
                })
            }
        })


        //获取群id
        // if(that.data.shareTicket != 0){
        //     wx.getShareInfo({
        //         shareTicket: that.data.shareTicket,
        //         success: function(res){
        //             console.log(res)
        //             let data = {
        //               "token": wx.getStorageSync("sessionId"),
        //               "iv": res.iv,
        //               "encryptedData": res.encryptedData
        //             }
        //             request.HttpRequst(true, 'program/decryptMsg', false, '', data, "post", false, res => {
        //               console.log(res)
        //               that.setData({
        //                 openGId: res.data.openGId
        //               })
        //             })
        //         },
        //         fail: function(){
        //             wx.showModal({
        //                 title: '提示',
        //                 content: '分享失败',
        //                 showCancel: false
        //             })
        //         }
        //     })
        // }

        //获取二维码
        request.HttpRequst(true, 'program/createPicCode', false, '', {'token': wx.getStorageSync("sessionId"),'scene':this.data.userId}, "post", false, res => {
            console.log(res);
            if(res.code == 200){
                this.setData({
                    qrCode: res.data
                })
            }
        })
        
    },
    onShow(options){
        //获取邀请信息
        request.HttpRequst(true, 'program/getShareData', false, '', {'token': wx.getStorageSync("sessionId")}, "post", false, res => {
            console.log(res)
            this.setData({
                count: res.data.count,
                money: res.data.money
            })
        })
    },
    //分享
    onShareAppMessage: function (res) {
        return {
            title: '【掌里通】帮我点一下，和我一起得5块大红包',
            path: '/pagesB/activity/hadShare/hadShare?userId='+this.data.userId+'&userHeaderUrl='+this.data.userHeaderUrl+'&userName'+this.data.userName,
            success: function(res) {
                console.log(res)
                wx.showModal({
                    title: '提示',
                    content: '分享成功',
                    showCancel: false
                })
                // 转发成功
                //let shareTicket = res.shareTickets;
                // wx.getShareInfo({
                //     shareTicket: shareTicket,
                //     success: function (res) {
                //         wx.showToast({
                //             title: '分享成功',
                //             duration: 3000
                //         })
                //     },
                //     fail: function (res) {
                //         console.log('fail');
                //         console.log(res);
                //         wx.showToast({
                //             title: '分享失败',
                //             duration: 3000
                //         })
                //     }
                // })

            },
            fail: function(res) {
                wx.showModal({
                    title: '提示',
                    content: '分享失败',
                    showCancel: false
                })
                // 分享失败
            }
        }
    },

    codeShare(){
        this.setData({
            seeCode: true
        })
    },

    //阻止冒泡事件
    touchMove() {
        
    },

    //隐藏二维码
    hiddenCode() {
        this.setData({
            seeCode: false
        })
    }
})